﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Empires.BLL.Core.IService;
using Empires.CRL.DataContract;
using Empires.RAL.Access;
using Empires.RAL.Pump;
using Empires.BLL.ServerProvider;

namespace Empires.BLL.Core.Implement
{
    public class CompanyBusinessService : ICompanyBusinessService
    {
        public List<DefaultDataPack> GetUtilsDetails(string copName, int type)
        {
            ICompanyBusinessAccess access = new CompanyBusinessDataPump();
            return access.GetUtilsDetails(copName, type);
        }

        public List<DefaultDataPack> GetBusinessDetail(string copname, int bid)
        {
            ICompanyBusinessAccess access = new CompanyBusinessDataPump();
            return access.GetBusinessDetail(copname, bid);
        }

        public List<DefaultDataPack> GetBusinessList(string copname,int page,int take, int type, int subject)
        {
            ICompanyBusinessAccess access = new CompanyBusinessDataPump();
            int itemCount = access.GetBusinessItemCount(copname, type, subject);
            return CompanyHelper.InjuectPagingInfo((currentPage) =>
            {
                return access.GetBusinessList(copname, currentPage, take, type, subject);
            },
            itemCount, page, take);

            //int pagecount = itemCount % take == 0 ? itemCount / take : itemCount / take + 1;
            //page = page < 0 ? 0 : page;
            //page = page > pagecount - 1 ? pagecount - 1 : page;
            //int previouspage = page == 0 ? 0 : page - 1;
            //int nextpage = page == pagecount - 1 ? pagecount - 1 : page + 1;
            //var list = 
            //return list.Select(c =>
            //{
            //    c.ITEMCOUNT = itemCount;
            //    c.PAGESIZE = take;
            //    c.CURRENTPAGE = page + 1;
            //    c.PAGECOUNT = pagecount;
            //    c.PREVIOUSPAGE = previouspage;
            //    c.NEXTPAGE = nextpage;
            //    c.FIRSTPAGE = 0;
            //    c.LASTPAGE = pagecount - 1;
            //    return c;
            //}).ToList();
        }


        public int BusinessItemDelete(string copname, int bid)
        {
            ICompanyBusinessAccess access = new CompanyBusinessDataPump();
            return access.BusinessItemDelete(copname, bid);
        }

        public bool EditBusinessItem(string copname, BusinessDataPack model)
        {
            ICompanyBusinessAccess service = new CompanyBusinessDataPump();
            return service.EditBusinessItem(copname, model);
        }

        public int AddBusinessItem(string copname, BusinessDataPack businessDataPack)
        {
            ICompanyBusinessAccess service = new CompanyBusinessDataPump();
            return service.AddBusinessItem(copname, businessDataPack);
        }


        public void UpdateBusiness(string copname, BusinessDataPack businessDataPack)
        {
            ICompanyBusinessAccess service = new CompanyBusinessDataPump();
            service.UpdateBusiness(copname, businessDataPack);
        }
    }
}
